#!/usr/bin/env python

import socket, sys, struct, binascii

host = "vortex.labs.pulltheplug.org"
port = 5842 

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))

s.sendall("GET / HTTP/1.0\n\n\r\n")

# receive 4 unsigned integer from server
# my problem => struct.error: unpack requires a string argument of length 4
# sometimes it works and sometimes don't 
# I don't understand because struct.calcsize("I") = 4
# the '!' is specific to network (choose the right endian)
a_oneInt = struct.unpack("!I",s.recv(struct.calcsize("I")))[0]
b_oneInt = struct.unpack("!I",s.recv(struct.calcsize("I")))[0]
c_oneInt = struct.unpack("!I",s.recv(struct.calcsize("I")))[0]
d_oneInt = struct.unpack("!I",s.recv(struct.calcsize("I")))[0]

#add them
sumInt = a_oneInt + b_oneInt + c_oneInt + d_oneInt

# send the sum back to the server
# problem sumInt seems to be a long...
s.send(struct.pack("i", sumInt))

#receive username and password from the server
answer = s.recv(2048)
print answer

